package yf.mall.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import java.util.Map;
import com.yf.consts.DaoConst;
import yf.mall.entity.StockRecordEntity;
import yf.mall.service.StockRecordService;
import com.yf.response.R;


/**
 * 库存记录Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Oct 09 09:56:41 CST 2019
 */
@RestController
@RequestMapping("/stockRecord")
public class StockRecordController {
    @Autowired
    private StockRecordService stockRecordService;

    /**
     * 列表库存记录
     */
    @RequestMapping("/list")
    @RequiresPermissions("stock:record:list")
    public R list(@RequestParam Map<String,Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<StockRecordEntity> stockRecordList = stockRecordService.queryList(params);
        return R.ok(new PageInfo(stockRecordList));
    }

    /**
     * 查看库存记录
     */
    @SysLog("查看库存记录")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("stock:record:info")
    public R info(@PathVariable("id") Long id) {
        StockRecordEntity stockRecord = stockRecordService.get(id);

        return R.ok(stockRecord);
    }

    /**
     * 保存库存记录
     */
    @SysLog("保存库存记录")
    @RequestMapping("/save")
    @RequiresPermissions("stock:record:save")
    public R save(StockRecordEntity stockRecord) {
        stockRecordService.save(stockRecord);

        return R.ok(stockRecord);
    }

    /**
     * 修改库存记录
     */
    @SysLog("修改库存记录")
    @RequestMapping("/update")
    @RequiresPermissions("stock:record:update")
    public R update(StockRecordEntity stockRecord) {
        stockRecordService.update(stockRecord);

        return R.ok(stockRecord);
    }

    /**
     * 删除库存记录
     */
    @SysLog("删除库存记录")
    @RequestMapping("/delete")
    @RequiresPermissions("stock:record:delete")
    public R delete(Long[]ids) {
        stockRecordService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有库存记录
     */
    @SysLog("所有库存记录")
    @RequestMapping("/queryAll")
    public R queryAll (@RequestParam Map<String,Object> params) {

        List<StockRecordEntity> stockRecordList = stockRecordService.queryList(params);

        return R.ok(stockRecordList);
    }

    /**
    @ModelAttribute
    public SearchParam<StockRecordEntity> searchParam(SearchParam<StockRecordEntity> params, StockRecordEntity stockRecord) {
        if (stockRecord != null) {
            params.setEntity(stockRecord);
        }

        return params;
    }
 **/
    /***********自定义开始***********/
}
